package com.tina;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author Tina
 * @version 1.0
 * @since 2021/11/17 16:03
 **/
public class Xshell {

    private static StringBuilder dockerfile(int port,String sourceFile, String fileName, String jdkVersion, String author) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("FROM " + jdkVersion + "\n");
        stringBuilder.append("MAINTAINER " + author  + "\n");
        stringBuilder.append("copy " + sourceFile + " /" + fileName  + "\n");
        stringBuilder.append("CMD java -jar /" + fileName  + "\n");
        stringBuilder.append("EXPOSE " + port);
        return stringBuilder;
    }

    public static void main(String[] args) {
        System.out.println(dockerfile(8080, "","tinaroot.jar", "openjdk:8-jre", "tina"));

    }

    private static void sh(String cmd) {
        try {
            String[] params = new String[]{"/bin/sh", "-c", cmd};
            Process ps = Runtime.getRuntime().exec(params);
            ps.waitFor();

            BufferedReader bufrIn = new BufferedReader(new InputStreamReader(ps.getInputStream(), "UTF-8"));
            BufferedReader bufrError = new BufferedReader(new InputStreamReader(ps.getErrorStream(), "UTF-8"));

            // 读取输出 result是shell中的输出
            StringBuilder result = new StringBuilder();
            String line = null;
            while ((line = bufrIn.readLine()) != null || (line = bufrError.readLine()) != null) {
                result.append(line).append('\n');
            }
            System.out.println(result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
